package com.ym.b2b.brand.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ym.b2b.brand.dao.EmBBrandDAO;
import com.ym.b2b.brand.service.EmBBrandService;
import com.ym.b2b.brand.sqlbean.EmBBrand;
import com.ym.b2b.commons.controller.BaseController;
import com.zc.commons.base.Page;
import com.zc.commons.base.Result;
import com.zc.export.ExcelUtil;

/***
 * @ClassName: ManagerEmBBrandContorller
 * @Description: 品牌 后台处理
 * @Author tangxiaojuan
 * @Date 2015年3月6日 下午4:05:13
 * @Modify
 * @CopyRight 珍诚医药在线股份有限公司
 */
@Controller
@RequestMapping("/brand")
public class ManagerEmBBrandContorller extends BaseController {

    @Autowired
    private EmBBrandService emBBrandService;

    @RequestMapping("showEmBBrandDetail.do")
    @ResponseBody
    public Result showEmBBrandDetail(EmBBrand emBBrand, HttpServletRequest req) {
        Result result = new Result();
        try {
            result = emBBrandService.showEmBBrandDetail(emBBrand);
        } catch (Exception e) {
            result.setCodeResult(Result.CODE_100, e.getMessage());
        }
        return result;
    }

    /***
     * @Title: searchPageProduct
     * @Description: 前台 采购商 列表界面
     * @Param @param EmBBrand
     * @Param @param page
     * @Param @param req
     * @Param @return
     * @Return Result
     * @Throws
     */
    @RequestMapping(value = "searchPageEmBBrand.do")
    public ResponseEntity<Result> searchPageEmBBrand(EmBBrand emBBrand, Page<EmBBrand> page, HttpServletRequest req) {
        Result result = new Result();
        try {
            result = emBBrandService.searchPageEmBBrand(page, emBBrand);
        } catch (Exception e) {
            result.setCodeResult(Result.CODE_100, e.getMessage());
        }
        return new ResponseEntity<Result>(result, getHeader(), HttpStatus.OK);
    }

    @RequestMapping(value = "searchPageEmBBrandExcel.do")
    @ResponseBody
    public Result searchPageEmBBrandExcel(EmBBrand emBBrand, Page<EmBBrand> page, String loadType) {
        Result result = new Result();
        try {
            if (loadType == null || loadType.equals("")) {
                result.setCode(Result.CODE_100);
                result.setResult("loadType 参数 '数量'  不能为空!");
                return result;
            }
            page.setPageable("true");
            page.setPageSize(Integer.parseInt(loadType));
            page.setStartRow(1);
            result = emBBrandService.searchPageEmBBrand(page, emBBrand);
            ExcelUtil<EmBBrand> excelUtil = new ExcelUtil<EmBBrand>();
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("model", result.getRows());
            result = excelUtil.createExcel("brandListExcel", map);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            result.setCodeResult(Result.CODE_100, e.getMessage());
        }
        return result;
    }

    @RequestMapping(value = "getEmBBrandList.do")
    @ResponseBody
    public Result getEmBBrandList(EmBBrand emBBrand, Page<EmBBrand> page, HttpServletResponse res) {
        Result result = new Result();
        try {
            result = emBBrandService.searchPageEmBBrand(page, emBBrand);
        } catch (Exception e) {
            result.setCodeResult(Result.CODE_100, e.getMessage());
        }
        return result;
    }

    @RequestMapping("insertEmBBrand.do")
    @ResponseBody
    public Result insertEmBBrand(EmBBrand EmBBrand, HttpServletRequest req) {
        Result result = new Result();
        try {
            result = emBBrandService.insertEmBBrand(EmBBrand);
        } catch (Exception e) {
            result.setCodeResult(Result.CODE_100, e.getMessage());
        }
        return result;
    }

    @RequestMapping("updateEmBBrand.do")
    @ResponseBody
    public Result updateEmBBrand(EmBBrand EmBBrand, HttpServletRequest req) {
        Result result = new Result();
        try {
            result = emBBrandService.updateEmBBrand(EmBBrand);
        } catch (Exception e) {
            result.setCodeResult(Result.CODE_100, e.getMessage());
        }
        return result;
    }

    @RequestMapping("deleteEmBBrand.do")
    @ResponseBody
    public Result deleteEmBBrand(EmBBrand EmBBrand, HttpServletRequest req) {
        Result result = new Result();
        try {
            result = emBBrandService.deleteEmBBrand(EmBBrand);
        } catch (Exception e) {
            result.setCodeResult(Result.CODE_100, e.getMessage());
        }
        return result;
    }

    // 批量审批
    @RequestMapping("editMultipleEmBBrandsStatus.do")
    @ResponseBody
    public Result editMultipleEmBBrandsStatus(String buyerIdList, HttpServletRequest req) {
        Result result = new Result();
        try {
            result = emBBrandService.editMultipleEmBBrandsStatus(buyerIdList);
        } catch (Exception e) {
            result.setCodeResult(Result.CODE_100, e.getMessage());
        }
        return result;
    }

    // 删除多条记录内容
    @RequestMapping("deleteMultipleEmBBrands.do")
    @ResponseBody
    public Result deleteMultipleEmBBrands(String brandIdList, HttpServletRequest req) {
        Result result = new Result();
        try {
            result = emBBrandService.deleteMultipleEmBBrands(brandIdList);
        } catch (Exception e) {
            result.setCodeResult(Result.CODE_100, e.getMessage());
        }
        return result;
    }

}
